package com.ihealthway.all.interfaces.dwihealth;

import com.ihealthway.all.interfaces.dwihealth.vo.BodyElement;
import com.ihealthway.all.interfaces.dwihealth.vo.ErrorInfoElement;
import com.ihealthway.all.interfaces.dwihealth.vo.HeadElement;
import com.ihealthway.all.interfaces.dwihealth.vo.InterProtocolResp;
import com.ihealthway.all.utils.JaxbUtil;

import java.util.List;

/**
 * XML content builder
 * @author  凡梦星尘(elkan1788@gmail.com)
 */
public class XMLBuilder {

    /**
     * 常见的操作返回
     * @param code      返回代码
     * @param comment   具体描述
     * @return  成功/错误返回
     */
    public static String simpleResp(String code, String comment, List<ErrorInfoElement> errors) {
        InterProtocolResp resp = new InterProtocolResp();
        HeadElement head = new HeadElement();
        head.setResultCode(code);
        head.setResultComment(comment);
        resp.setHead(head);

        if (errors!=null) {
            BodyElement body = new BodyElement();
            body.setCustInfoErrors(errors);
            resp.setBody(body);
        }

        return JaxbUtil.toXML(resp, "TXLife");
    }


    /**
     * 常见简易的操作返回
     * @param code      返回代码
     * @param comment   具体描述
     * @return  成功/错误返回
     */
    public static String simpleResp(String code, String comment) {
        InterProtocolResp resp = new InterProtocolResp();
        HeadElement head = new HeadElement();
        head.setResultCode(code);
        head.setResultComment(comment);
        resp.setHead(head);
        return JaxbUtil.toXML(resp, "TXLife");
    }
}
